<template>
	<view class="wrap">
		<view class="tips">
			<uni-icons type="info" size="20" color="#FF2D2D"></uni-icons> 提示：请先下载批量导入的格式文件，按照格式要求填充内容后，再导入文件进行批量导入。
		</view>
		<view class="download" @click="download">
			点击下载格式文件工人信息模板.XLS
		</view>
		<uni-file-picker file-mediatype="all" @select="select" file-extname="xlsx">
			<view class="submitBtn">
				上传文件
			</view>
		</uni-file-picker>
	</view>
</template>

<script>
	import {
		domain
	} from "@/utis/request.js"
	export default {
		data() {
			return {
				fileUrl: ''
			}
		},
		onLoad() {},
		methods: {
			download() {
				// this.$loanding("下载中")
				this.$post("/worker/download_template").then(res => {
					uni.downloadFile({
						url: res.data,
						success: function(result) {
							var filePath = result.tempFilePath;
							uni.openDocument({
								filePath: filePath,
								showMenu: true,
								success: function(res) {
									console.log('打开文档成功');
								}
							});
						}
					});
				})
			},
			select(e) {
				console.log(e)
				this.$loanding("上传中")
				e.tempFilePaths.forEach(item => {
					uni.uploadFile({
						url: domain + 'api/worker/import',
						header: {
							'token': uni.getStorageSync('token'),
						},
						filePath: item,
						name: 'file',
						success: (res) => {
							console.log(res)
							uni.hideLoading()
						},
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tips {
		color: #FF2D2D;
		background: #F6EAEA;
		border-radius: 16rpx;
		padding: 20rpx;
		font-size: 28rpx;
		line-height: 2;
		margin-top: 40rpx;

	}

	::v-deep uni-icons {
		transform: translateY(8rpx);
	}

	.download {
		color: $main-color;
		font-size: 30rpx;
		margin: 50rpx 0 90rpx;
	}
</style>